package com.czxy.controller;

import com.czxy.domain.Health;
import com.czxy.domain.HealthVo;
import com.czxy.service.HealthService;
import com.czxy.vo.BaseResult;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author zhangmengxiang1@itcast.cn
 * @version 1.0
 * @date 2020/2/11
 */
@RestController
@RequestMapping("/health")
public class HealthController {

    @Resource
    private HealthService healthService;

    //查询 所有的卫生
    @PostMapping("/findAllHealthBypage")
    public BaseResult findAllHealthBypage(@RequestBody HealthVo healthVo){
        PageInfo<Health> pageInfo = healthService.findAllHealthBypage(healthVo);
        return BaseResult.ok("查询成功",pageInfo);
    }

    @GetMapping("/findOneByhid/{hid}")
    public BaseResult findOneByhid(@PathVariable("hid") Integer hid){
       Health health =  healthService.findOneByhid(hid);
       return BaseResult.ok("查询成功",health);
    }

    //修改
    @PutMapping("/updateHealth")
    public BaseResult updateHealth(@RequestBody Health health){
        System.out.println(health);
        healthService.updateHealth(health);
        return BaseResult.ok("修改成功");
    }

    //删除卫生
    @DeleteMapping("/delhealthbyhid/{hid}")
    public BaseResult delhealthbyhid(@PathVariable("hid") Integer hid){
        healthService.delhealthbyhid(hid);
        return BaseResult.ok("删除成功");
    }
}
